home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / COSEmulator / COSEmulator- SRC / src / MenuBar.cpp < prev    next >
Encoding:
Text File  |  1998-06-21  |  7.9 KB  |  353 lines  |  [TEXT/CWIE]

  1. //===================================================================
  2. //=======================  Headers        =============================
  3.  
  4. #include "MenuBar.h"
  5. #include "GameUtilities.h"
  6. #include "Screen.h"
  7. #include "ApplicationHandler.h"
  8.  
  9. //===================================================================
  10. //=======================  Globals        =============================
  11.  
  12. MenuBar        menuBar;
  13.  
  14. //===================================================================
  15. //=======================  #define        =============================
  16.  
  17.  
  18. //===================================================================
  19. //=======================  Function Prototypes    =====================
  20.  
  21.  
  22. /*----------------------------------------------------------------------------\
  23.  
  24.     MenuBar :: Constructor
  25.  
  26. \----------------------------------------------------------------------------*/
  27.     MenuBar :: MenuBar( void )
  28. {
  29.     MySetRect( &menuBarLoc , 0 , 0 , 1024 , 20 );
  30.     
  31.     menuDown = false;
  32.     activeSelect = false;
  33.     which = 0;
  34.     
  35.     numMenu = 2;
  36.     
  37.     short    i;
  38.     
  39.     for( i = 0; i < kMaxMenuBarItems; i++ )
  40.         menus[ i ] = NULL;
  41.         
  42. }
  43.  
  44. /*----------------------------------------------------------------------------\
  45.  
  46.     MenuBar :: Init
  47.  
  48. \----------------------------------------------------------------------------*/
  49. Boolean    MenuBar :: Init( void )
  50. {
  51.     Boolean    allGood;
  52.     
  53.     allGood = backGround.LoadPicBuff( 130 );
  54.  
  55.     if( allGood )
  56.         allGood = menuBar.NewBuff( 1024 , 20 );
  57.         
  58.     if( allGood )
  59.     {
  60.         DrawPicture( &backGround , &backGround.GetBoundsSize() ,
  61.                      &menuBar , &menuBar.GetBoundsSize() );
  62.     }
  63.     return allGood;
  64. }
  65.  
  66. /*----------------------------------------------------------------------------\
  67.  
  68.     MenuBar :: HandleMouseClick
  69.  
  70. \----------------------------------------------------------------------------*/
  71. Boolean    MenuBar :: HandleMouseClick( Boolean down , point where )
  72. {
  73.  
  74.     if( !menuDown )
  75.     {
  76.         if( down )
  77.         {
  78.             short    i;
  79.             
  80.             for( i = 0; i < numMenu - 1 ; i++ )
  81.             {
  82.                 if( menus[ i ]->PointInTitle( where ) )
  83.                 {
  84.                      menus[ i ]->SetActive( true );
  85.                      which = i;
  86.                      menuDown = true;
  87.                      activeSelect = true;
  88.                      return true;
  89.                 }
  90.             }
  91.         
  92.             if( menus[ kProgramList ]->PointInTitle( where ) )
  93.             {
  94.                 menus[ kProgramList ]->SetActive( true );
  95.                 which = kProgramList;
  96.                 menuDown = true;
  97.                 activeSelect = true;
  98.                 return true;
  99.             }
  100.             
  101.         }
  102.         else if( activeSelect )
  103.             activeSelect = false;
  104.         
  105.     }
  106.     else
  107.     {
  108.         menus[ which ]->SetActive( false );
  109.         menuDown = false;
  110.         activeSelect = false;
  111.     }
  112.     
  113.     return SectPtRect( where , menuBarLoc );
  114. }
  115.  
  116. /*----------------------------------------------------------------------------\
  117.  
  118.     MenuBar :: HandleMouseMove
  119.  
  120. \----------------------------------------------------------------------------*/
  121. void    MenuBar :: HandleMouseMove( point where )
  122. {
  123.     if( menuDown )
  124.     {
  125.         if( !menus[ which ]->PointInTitle( where ) )
  126.         {
  127.             if( !SectPtRect( where , menuBarLoc ) )
  128.                 return;
  129.                 
  130.             menus[ which ]->SetActive( false );
  131.             menuDown = false;
  132.             
  133.             HandleMouseClick( true , where );
  134.         }
  135.     }
  136.     else if( activeSelect )
  137.     {
  138.         HandleMouseClick( true , where );
  139.     }
  140. }
  141. /*----------------------------------------------------------------------------\
  142.  
  143.     MenuBar :: UpdateMenuBar
  144.  
  145. \----------------------------------------------------------------------------*/
  146. void    MenuBar :: UpdateMenuBar( rect *where )
  147. {
  148.     where = NULL;
  149.     
  150.     DrawAllList( where );
  151.     
  152.     if( where == NULL )
  153.     {
  154.         screen.DrawGeneric( &menuBar , &menuBar.GetBoundsSize() , 
  155.                             &menuBarLoc , NULL ,
  156.                             0 , 0 , 0 , true);
  157.     }
  158.     else
  159.     {
  160.         rect    loc;
  161.         MyCropRect( where , &menuBarLoc , &loc );
  162.         
  163.         screen.DrawGeneric( &menuBar , &loc , 
  164.                             &loc , NULL ,
  165.                             0 , 0 , 0 , true);
  166.     }    
  167. }
  168.  
  169. /*----------------------------------------------------------------------------\
  170.  
  171.     MenuBar :: ClearMenuList
  172.  
  173. \----------------------------------------------------------------------------*/
  174. void    MenuBar :: ClearMenuList( void )
  175. {
  176.     short    i;
  177.  
  178.     if( menuDown )
  179.         menus[ which ]->SetActive( false );
  180.         
  181.         
  182.     for( i = 1; i < numMenu - 1; i++ )
  183.     {
  184.         if( menus[ i ] != NULL )
  185.             menus[ i ]->AddRectToUpdate();
  186.                 
  187.         menus[ i ] = NULL;
  188.     }
  189.     
  190.     screen.AddRectToUpdate( menuBarLoc );
  191.     
  192.     activeSelect = false;
  193.     menuDown = false;
  194.     numMenu = 0;
  195. }
  196.  
  197. /*----------------------------------------------------------------------------\
  198.  
  199.     MenuBar :: AddMenuToList
  200.  
  201. \----------------------------------------------------------------------------*/
  202. void    MenuBar :: AddMenuToList( MenuItem *blarg )
  203. {
  204.     if( numMenu < kMaxMenuBarItems )
  205.     {
  206.         menus[ numMenu - 1 ] = blarg;
  207.         menus[ numMenu - 1 ]->SetLocation( menus[ numMenu - 2 ]->GetLoc().right );
  208.         blarg->AddRectToUpdate();
  209.         
  210.         numMenu++;
  211.     }
  212. }
  213.  
  214. /*----------------------------------------------------------------------------\
  215.  
  216.     MenuBar :: AddAppToList
  217.  
  218. \----------------------------------------------------------------------------*/
  219. void    MenuBar :: AddAppToList( uchar app )
  220. {
  221.  
  222.     switch( app )
  223.     {
  224.     case kFinderApp:
  225.         menus[ kProgramList ]->AddItem( menus[ kProgramList ]->GetNumItems() ,
  226.                           "Finder" , true );
  227.     break;
  228.     
  229.     case kPhotoshopApp:
  230.         menus[ kProgramList ]->AddItem( menus[ kProgramList ]->GetNumItems() ,
  231.                           "Photoshop" , true );
  232.     break;
  233.  
  234.     case kMacAmp:
  235.         menus[ kProgramList ]->AddItem( menus[ kProgramList ]->GetNumItems() ,
  236.                           "MacAmp" , true );
  237.     break;
  238.         
  239.     case kQuickTime:
  240.         menus[ kProgramList ]->AddItem( menus[ kProgramList ]->GetNumItems() ,
  241.                           "MoviePlayer" , true );
  242.     break;
  243.     
  244.     default:
  245.         menus[ kProgramList ]->AddItem( menus[ kProgramList ]->GetNumItems() ,
  246.                           "Unknown" , true );
  247.     break;
  248.     }
  249. }
  250. /*----------------------------------------------------------------------------\
  251.  
  252.     MenuBar :: DrawGeneric
  253.  
  254. \----------------------------------------------------------------------------*/
  255. void    MenuBar :: DrawGeneric(     OffScreenBuff *srcBuff , rect *srcRect , 
  256.                                 rect *destRect , rect *crop , ushort options , 
  257.                                 uchar more , ushort color )
  258. {
  259.     if( crop == NULL )
  260.     {    
  261.         ::DrawGeneric( srcBuff , srcRect , &menuBar , destRect , 
  262.                      &menuBarLoc , kDrawCrop1 | options, more , color );
  263.  
  264.     }
  265.     else
  266.     {
  267.         rect    where;
  268.         
  269.         MyCropRect( crop , &menuBarLoc , &where );
  270.         
  271.         ::DrawGeneric( srcBuff , srcRect , &menuBar , destRect ,
  272.                      &where , kDrawCrop1 | options , more , color );
  273.     }
  274. }
  275.  
  276. /*----------------------------------------------------------------------------\
  277.  
  278.     MenuBar :: DrawAllList
  279.  
  280. \----------------------------------------------------------------------------*/
  281. void    MenuBar :: DrawAllList( rect *where )
  282. {
  283.     short    i;
  284.  
  285.     if( where != NULL )
  286.     {
  287.         ::DrawGeneric( &backGround , &backGround.GetBoundsSize() ,
  288.                      &menuBar , &menuBarLoc , where ,
  289.                      kDrawCrop1 , 0 , 0 ); 
  290.     }
  291.     else
  292.     {
  293.         DrawPicture( &backGround , &backGround.GetBoundsSize() , &menuBar , &menuBarLoc );
  294.     }
  295.     
  296.     for( i = 0; i < numMenu - 1 ; i++ )
  297.     {
  298.          menus[ i ]->DrawMenu( where );
  299.     }
  300.     
  301.      menus[ kProgramList ]->DrawMenu( where );
  302. }
  303.  
  304. /*----------------------------------------------------------------------------\
  305.  
  306.     MenuBar :: HandleSpecialMenuSelect
  307.  
  308. \----------------------------------------------------------------------------*/
  309. void    MenuBar :: HandleSpecialMenuSelect( uchar which , uchar select )
  310. {
  311.     switch( which )
  312.     {
  313.     case kAppleMenuTitle:
  314.         
  315.     break;
  316.     
  317.     case kAppListMenuTitle:
  318.         if( select > 3 )
  319.             AH.SwitchToAppByNum( select - 4 );        
  320.     break;
  321.     }
  322. }
  323.  
  324. /*----------------------------------------------------------------------------\
  325.  
  326.     MenuBar :: SetUpSpecialMenu
  327.  
  328. \----------------------------------------------------------------------------*/
  329. void    MenuBar :: SetUpSpecialMenu( MenuItem *appleMenu , MenuItem *appSwitchMenu )
  330. {
  331.     appleMenu->SetWhichMenu( kAppleMenuTitle );
  332.     appleMenu->SetMaxItems( 30 );
  333.     appleMenu->SetLocation( 10 );
  334.     appleMenu->Init();
  335.     
  336.     appSwitchMenu->SetWhichMenu( kAppListMenuTitle );
  337.     appSwitchMenu->SetMaxItems( 4 );
  338.     appSwitchMenu->SetLocation( 1024 - 40 );
  339.     
  340.     appSwitchMenu->AddItem( 0 , "Hide Current App" , true );
  341.     appSwitchMenu->AddItem( 1 , "Hide Others" , true );
  342.     appSwitchMenu->AddItem( 2 , "Show All" , true );
  343.     appSwitchMenu->AddItem( 3 , "\0" , true );
  344.     
  345.     appSwitchMenu->Init();
  346.     
  347.     menus[ kAppleMenu ] = appleMenu;
  348.     menus[ kProgramList ] = appSwitchMenu;
  349.     
  350.     numMenu = 2;
  351.  
  352. }
  353.